﻿/// <reference path="../Turbo/Turbo_common.js" />
/// <reference path="PagerSettings.js" />
// <reference path="Repeater.js" />

var ____a;

var $RepeaterPageButton = TA.Turbo.Controls.RepeaterPageButton = function RepeaterPageButton(element, repeater)
{
	if (Function.IsInherit(arguments)) return;

	this.EventSender();

	this._element = element;
	this._repeater = repeater;
	this._visible = this._element.style["display"] != "none";
	this._clickHandler = this.OnClick.bind(this);

	for (var i = 0; i < this._element.childNodes.length; ++i)
	{
		var c = this._element.childNodes[i];
		switch (c.nodeName)
		{
			case "#text":
				this._txt = c; break;
			case "IMG":
				this._img = c; break;
		}
	}
	if (this._txt == null)
		this._txt = document.createTextNode(" ");
}
$RepeaterPageButton.Inherit(EventSender);
if (____a)
{
	$RepeaterPageButton.prototype = new EventSender();
	$RepeaterPageButton.prototype.EventSender = new EventSender();

	$RepeaterPageButton.prototype._visible = true;
	$RepeaterPageButton.prototype._element = document.createElement("asd");
	$RepeaterPageButton.prototype._text = document.createElement("asd");
	$RepeaterPageButton.prototype._img = document.createElement("asd");
	$RepeaterPageButton.prototype._clickHandler = null;
	$RepeaterPageButton.prototype._repeater = null;
}

$RepeaterPageButton.prototype.OnClick = function OnClick(e)
{
	this.RaiseEvent("PageIndexChanged", { PageIndex: this.get_Index() });

	return false;
}
$RepeaterPageButton.prototype.get_Index = function get_Index()
{ // ABSTRACT
}
$RepeaterPageButton.prototype.get_PagerElement = function get_PagerElement()
{ // ABSTRACT
	return new $PagerElement();
}
$RepeaterPageButton.prototype.get_PagerSettings = function get_PagerSettings()
{
	return this._repeater.get_Pager();
	//	var args = { PagerSettings: 0 };
	//	this.RaiseEvent("GetPagerSettings", args);
	//	return args.PagerSettings;
	return new $PagerSettings();
}
$RepeaterPageButton.prototype.get_CurrentPageIndex = function get_CurrentPageIndex()
{
	return this._repeater.get_ActualPageIndex();
	//	var args = { PageIndex: 0 };
	//	this.RaiseEvent("GetCurrentPageIndex", args);
	//	return args.PageIndex;
}
$RepeaterPageButton.prototype.get_NumPages = function get_NumPages()
{
	return this._repeater.get_NumPages();
	//	var args = { NumPages: 0 };
	//	this.RaiseEvent("GetNumPages", args);
	//	return args.NumPages;
}
$RepeaterPageButton.prototype.get_Visible = function get_Visible()
{
	return this._visible;
}
$RepeaterPageButton.prototype.set_Visible = function set_Visible(value)
{
	this._visible = value;
	this._element.style["display"] = this._visible ? "" : "none";
}
$RepeaterPageButton.prototype.IsSelected = function IsSelected()
{
	return this.get_Index() == this.get_CurrentPageIndex();
}
$RepeaterPageButton.prototype.UpdateStatus = function UpdateStatus()
{
	if (this.IsSelected())
	{
		this._element.removeAttribute("href");
		this._element.onclick = null;
	}
	else
	{
		var hrefJs = this.get_PagerElement().HrefJS;
		if (hrefJs == null || hrefJs == "")
			hrefJs = this.get_PagerSettings().ButtonHrefJS;
		if (hrefJs == null || hrefJs == "")
		{
			this._element.setAttribute("href", " ");
			this._element.onclick = this._clickHandler;
		}
		else
		{
			this._element.setAttribute("href", hrefJs.Replace("###", this.get_Index() + 1));
			this._element.onclick = null;
		}
	}
}
$RepeaterPageButton.prototype.UpdateStyle = function UpdateStyle()
{
	this._element.style["display"] = this._visible && this.get_PagerElement().Visible ? "" : "none";

	$(this._element).ClearChildNodes();
	this._txt.nodeValue = this.get_PagerElement().Text.Replace("###", this.get_Index() + 1);

	var imageUrl = this.get_PagerElement().ImageUrl;
	if (imageUrl != null && imageUrl != "")
	{
		this._img.src = imageUrl.Replace("###", this.get_Index());

		switch (settings.TextImageRelation)
		{
			//		case $TextImageRelation.Overlay:                                      
			//			if(txt != null) elem.appendChild(txt);                                      
			//			if(img != null) elem.appendChild(img);                                      
			//			break;                                      
			case $TextImageRelation.TextBeforeImage:
				this._element.appendChild(this._txt);
				this._element.appendChild(this._img);
				break;
			case $TextImageRelation.ImageBeforeText:
				this._element.appendChild(this._img);
				this._element.appendChild(this._txt);
				break;
			case $TextImageRelation.TextAboveImage:
				this._element.appendChild(this._txt);
				this._element.appendChild(document.createElement("br"));
				this._element.appendChild(this._img);
				break;
			case $TextImageRelation.ImageAboveText:
				this._element.appendChild(this._img);
				this._element.appendChild(document.createElement("br"));
				this._element.appendChild(this._txt);
				break;
		}
	}
	else
	{
		this._element.appendChild(this._txt);
	}
}














var $RepeaterPageButtonFirst = TA.Turbo.Controls.RepeaterPageButtonFirst = function RepeaterPageButtonFirst(element, repeater)
{
	this.RepeaterPageButton(element, repeater);
}
$RepeaterPageButtonFirst.Inherit($RepeaterPageButton);
if (____a)
{
	$RepeaterPageButtonFirst.prototype = new $RepeaterPageButton();
	$RepeaterPageButtonFirst.prototype.RepeaterPageButton = new $RepeaterPageButton();
}
$RepeaterPageButtonFirst.prototype.get_Index = function get_Index()
{
	return 0;
}
$RepeaterPageButtonFirst.prototype.get_PagerElement = function get_PagerElement()
{
	return this.get_PagerSettings().First;
}


var $RepeaterPageButtonPrevious = TA.Turbo.Controls.RepeaterPageButtonPrevious = function RepeaterPageButtonPrevious(element, pagerElement)
{
	this.RepeaterPageButton(element, pagerElement);
}
$RepeaterPageButtonPrevious.Inherit($RepeaterPageButton);
if (____a)
{
	$RepeaterPageButtonPrevious.prototype = new $RepeaterPageButton();
	$RepeaterPageButtonPrevious.prototype.RepeaterPageButton = new $RepeaterPageButton();
}
$RepeaterPageButtonPrevious.prototype.get_Index = function get_Index()
{
	return Math.max(0, this.get_CurrentPageIndex() - 1);
}
$RepeaterPageButtonPrevious.prototype.get_PagerElement = function get_PagerElement()
{
	return this.get_PagerSettings().Previous;
}





var $RepeaterPageButtonPreviousGroup = TA.Turbo.Controls.RepeaterPageButtonPreviousGroup = function RepeaterPageButtonPreviousGroup(element, repeater)
{
	this.RepeaterPageButton(element, repeater);
}
$RepeaterPageButtonPreviousGroup.Inherit($RepeaterPageButton);
if (____a)
{
	$RepeaterPageButtonPreviousGroup.prototype = new $RepeaterPageButton();
	$RepeaterPageButtonPreviousGroup.prototype.RepeaterPageButton = new $RepeaterPageButton();
}
$RepeaterPageButtonPreviousGroup.prototype.get_Index = function get_Index()
{
	return Math.max(0, this.get_CurrentPageIndex() - this.get_PagerSettings().ButtonCount);
}
$RepeaterPageButtonPreviousGroup.prototype.get_PagerElement = function get_PagerElement()
{
	return this.get_PagerSettings().PreviousGroup;
}
$RepeaterPageButtonPreviousGroup.prototype.IsSelected = function IsSelected()
{
	return this._repeater.get_PagesRange().Start == 0;
}
$RepeaterPageButtonPreviousGroup.prototype.UpdateStatus = function UpdateStatus()
{
	this.RepeaterPageButton.UpdateStatus.call(this);

	this._element.style["visibility"] = this.IsSelected() ? "hidden" : "visible";
}







var $RepeaterPageButtonNextGroup = TA.Turbo.Controls.RepeaterPageButtonNextGroup = function RepeaterPageButtonNextGroup(element, repeater)
{
	this.RepeaterPageButton(element, repeater);
}
$RepeaterPageButtonNextGroup.Inherit($RepeaterPageButton);
if (____a)
{
	$RepeaterPageButtonNextGroup.prototype = new $RepeaterPageButton();
	$RepeaterPageButtonNextGroup.prototype.RepeaterPageButton = new $RepeaterPageButton();
}
$RepeaterPageButtonNextGroup.prototype.get_Index = function get_Index()
{
	return Math.min(this.get_CurrentPageIndex() + this.get_PagerSettings().ButtonCount, this.get_NumPages() - 1);
}
$RepeaterPageButtonNextGroup.prototype.get_PagerElement = function get_PagerElement()
{
	return this.get_PagerSettings().NextGroup;
}
$RepeaterPageButtonNextGroup.prototype.IsSelected = function IsSelected()
{
	return this._repeater.get_PagesRange().End == this._repeater.get_NumPages();
}

$RepeaterPageButtonNextGroup.prototype.UpdateStatus = function UpdateStatus()
{
	this.RepeaterPageButton.UpdateStatus.call(this);

	this._element.style["visibility"] = this.IsSelected() ? "hidden" : "visible";
}







var $RepeaterPageButtonNext = TA.Turbo.Controls.RepeaterPageButtonNext = function RepeaterPageButtonNext(element, repeater)
{
	this.RepeaterPageButton(element, repeater);
}
$RepeaterPageButtonNext.Inherit($RepeaterPageButton);
if (____a)
{
	$RepeaterPageButtonNext.prototype = new $RepeaterPageButton();
	$RepeaterPageButtonNext.prototype.RepeaterPageButton = new $RepeaterPageButton();
}
$RepeaterPageButtonNext.prototype.get_Index = function get_Index()
{
	return Math.min(this.get_CurrentPageIndex() + 1, this.get_NumPages() - 1);
}
$RepeaterPageButtonNext.prototype.get_PagerElement = function get_PagerElement()
{
	return this.get_PagerSettings().Next;
}






var $RepeaterPageButtonLast = TA.Turbo.Controls.RepeaterPageButtonLast = function RepeaterPageButtonLast(element, repeater)
{
	this.RepeaterPageButton(element, repeater);
}
$RepeaterPageButtonLast.Inherit($RepeaterPageButton);
if (____a)
{
	$RepeaterPageButtonLast.prototype = new $RepeaterPageButton();
	$RepeaterPageButtonLast.prototype.RepeaterPageButton = new $RepeaterPageButton();
}
$RepeaterPageButtonLast.prototype.get_Index = function get_Index()
{
	return this.get_NumPages() - 1;
}
$RepeaterPageButtonLast.prototype.get_PagerElement = function get_PagerElement()
{
	return this.get_PagerSettings().Last;
}




















var $RepeaterPageButtonNormal = TA.Turbo.Controls.RepeaterPageButtonNormal = function RepeaterPageButtonNormal(element, repeater)
{
	this.RepeaterPageButton(element, repeater);
}
$RepeaterPageButtonNormal.Inherit($RepeaterPageButton);
if (____a)
{
	$RepeaterPageButtonNormal.prototype = new $RepeaterPageButton();
	$RepeaterPageButtonNormal.prototype.RepeaterPageButton = new $RepeaterPageButton();

	$RepeaterPageButtonNormal.prototype._index = 0;
}
$RepeaterPageButtonNormal.prototype.get_Index = function get_Index()
{
	return this._index;
}
$RepeaterPageButtonNormal.prototype.SetIndex = function SetIndex(index)
{
	this._index = index;
}
$RepeaterPageButtonNormal.prototype.UpdateStatus = function UpdateStatus(index)
{
	this.RepeaterPageButton.UpdateStatus.call(this, index);

	if (this.IsSelected(index))
	{
		this._element.AddClass("selected");
	}
	else
	{
		this._element.RemoveClass("selected");
	}
}
$RepeaterPageButtonNormal.prototype.get_PagerElement = function get_PagerElement()
{
	return this.get_PagerSettings().Normal;
}









